<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="java.util.List"%>
<%@page import="java.util.Map"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<%@taglib uri="/jstl/cout" prefix="c"%>
<head>
<%
String contextPath=request.getContextPath();
%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="${contextPath}/common/jsp_head_new.jsp" />
<title> 需求预测调整 </title>
<script language="JavaScript" src="<%=contextPath %>/js/ut.js"></script>

<script language="JavaScript"><!--
       function executeQueryOpe(){
       		document.getElementById("tb2").style.display='none';
       		document.getElementById("btns").style.display="none";
		    var areaId=document.getElementById("areaId").value;
			var url = "<%=contextPath%>/sales/planmanage/RequirementForecast/RequireForecastManage/requireForecastReportModelSearch.json";
			makeCall(url,showJson,{areaId:areaId});
       }
       //构建页面
		function showJson(json){
			var ymlist=json.mapList;
			var infolist=json.infoList;
			//清空数据
			var tbody=document.getElementById("tbody1");
			clrTbody(tbody);
			//如果没有返回结果，显示无数据提示页
			if(ymlist.length==0||null==infolist){
				showNoRsTable();
				return;
			}
	
			var thtr=document.createElement("tr");
			var thtr1=document.createElement("tr");
			var scth=document.createElement("th");
			scth.rowSpan=2;
			scth.appendChild(document.createTextNode("车系代码"));
			var snth=document.createElement("th");
			snth.rowSpan=2;
			snth.appendChild(document.createTextNode("车系名称"));
			var mcth=document.createElement("th");
			mcth.rowSpan=2;
			mcth.appendChild(document.createTextNode("车型代码"));
			var mnth=document.createElement("th");
			mnth.rowSpan=2;
			mnth.appendChild(document.createTextNode("车型名称"));
			thtr.appendChild(scth);
			thtr.appendChild(snth);
			thtr.appendChild(mcth);
			thtr.appendChild(mnth);
			for(var i=0;i<ymlist.length;i++){
				var th=document.createElement("th");
				th.colSpan=2;
				th.align="center";
				th.appendChild(document.createTextNode(ymlist[i].YEAR+'-'+ymlist[i].MONTH));
				thtr.appendChild(th);
				var th1=document.createElement("th");
				var th2=document.createElement("th");
				th1.appendChild(document.createTextNode("下级汇总"));
				th2.appendChild(document.createTextNode("预测数量"));
				thtr1.appendChild(th1);
				thtr1.appendChild(th2);
			}
			var opth=document.createElement("th");
			opth.rowSpan=2;
			opth.appendChild(document.createTextNode("操作"));
			thtr.appendChild(opth);
			tbody.appendChild(thtr);
			tbody.appendChild(thtr1);
			
			for(var i=0;i<infolist.length;i++){
       			var tdtr=document.createElement("tr");
       			var trclass;
       			if(i%2!=0){
       				tdtr.className="table_list_row1";
       			}else{
       				tdtr.className="table_list_row2";
       			}
       			var sctd=document.createElement("td");
       			sctd.appendChild(document.createTextNode(infolist[i].SERIES_CODE));
       			var sntd=document.createElement("td");
       			sntd.appendChild(document.createTextNode(infolist[i].SERIES_NAME));
       			var mctd=document.createElement("td");
       			mctd.appendChild(document.createTextNode(infolist[i].MODEL_CODE));
       			var mntd=document.createElement("td");
       			mntd.appendChild(document.createTextNode(infolist[i].MODEL_NAME));
       			tdtr.appendChild(sctd);
       			tdtr.appendChild(sntd);
       			tdtr.appendChild(mctd);
       			tdtr.appendChild(mntd);
       		    for(var j=0;j<ymlist.length;j++){
       		    	var td1=document.createElement("td");
       		    	td1.appendChild(document.createTextNode(infolist[i]['D'+j]));
       		    	var td2=document.createElement("td");
       		    	td2.appendChild(document.createTextNode(infolist[i]['S'+j]));
       		    	tdtr.appendChild(td1);
       		    	tdtr.appendChild(td2);
       		    }
       		    var optd=document.createElement("td");
       		    var ipt=document.createElement("a");
				ipt.href='#';
				ipt.name=infolist[i].GROUP_ID;
				ipt.innerHTML="[调整]";
				ipt.onclick= function(){
					document.getElementById("modelId").value=this.name;
		       	    var url ="<%=contextPath%>/sales/planmanage/RequirementForecast/RequireForecastManage/requireForecastSearch.do";
		       	    form1.action=url;
		       	    form1.method='post';
		       	    form1.submit();
				};
				optd.appendChild(ipt);
				tdtr.appendChild(optd);
       		    tbody.appendChild(tdtr);
       		}
       		document.getElementById("btns").style.display="inline";
       		document.getElementById("area").value=json.areaId;
		}
      
        function clrTbody(obj){
	        for(var i=0,len = obj.rows.length;i<len;i++){
               obj.deleteRow(0);
			}
	    }
       function showNoRsTable(){
       		document.getElementById("tb2").style.display='inline';
       }
       
        function isReport(){
      	 MyConfirm("是否确认上报信息?",reportSubmit);
       }
       function reportSubmit(){
       	   var url ="<%=contextPath%>/sales/planmanage/RequirementForecast/RequireForecastManage/requireForecastReport.do";
       	   form1.action=url;
       	   form1.method='post';
       	   form1.submit();
       }
       function showUnreport(){
           var areaId=document.getElementById("area").value;
           OpenHtmlWindow("<%=contextPath%>/sales/planmanage/RequirementForecast/RequireForecastManage/unreportForwardAction.do?area="+areaId,800,500);
       
       }
        function showLessreport(){
           var areaId=document.getElementById("area").value;
           OpenHtmlWindow("<%=contextPath%>/sales/planmanage/RequirementForecast/RequireForecastManage/lessReportForwardAction.do?area="+areaId,800,500);
       
       }

</script>
</head>

<body onload="executeQueryOpe();">
	<div class="wbox">
	<div class="navigation"><img src="<%=contextPath %>/img/nav.gif" />&nbsp;当前位置>计划管理>需求预测> 需求预测调整
	</div>
<form name="fm" method="post" id="fm">
<table class="table_query" id="subtab" >
  <tr class="csstr">
    <td> 请选择业务范围：
      <select name="areaId" id="areaId" onchange="executeQueryOpe();">
	       <c:forEach items="${areaBusList}" var="areaBusList" >
	       		<c:if test="${areaId == areaBusList.AREA_ID}">
	       			<option selected="selected" value="${areaBusList.AREA_ID },${areaBusList.DEALER_ID }">${areaBusList.AREA_NAME }</option>
	       		</c:if>
	       		<c:if test="${areaId != areaBusList.AREA_ID}">
	       			<option value="${areaBusList.AREA_ID },${areaBusList.DEALER_ID }">${areaBusList.AREA_NAME }</option>
	       		</c:if>
		   </c:forEach>
      </select>
    </td>
    <td>
    	<input type="button" id="queryBtn" class="cssbutton"  value="查询" onclick="executeQueryOpe();" />
    </td>
  </tr>  
</table>
</form>
<form name="form1" id="form1">
	<table style="display: none">
		<tr>
			<td align="center">
				<input type="hidden" name="modelId" id="modelId" value="" />
			    <input type="hidden" name="area" id="area" value="" />
	     	</td>
		</tr>
	</table>
</form>
</div>
<p>&nbsp;</p>
<table class="table_list" id="tb1" >
<tbody id="tbody1"></tbody>
</table>
<table class=table_query style="display:none" id="btns">
  <tr>
     <td>
	     <input name="button" type="button" class="normal_btn" onclick="isReport();" value="上报/完成" />
	     <input name="button3" type="button" class="long_btn" onclick="showUnreport();" value="未提报经销商名单" />
	     <input name="button2" type="button" class="long_btn" style="width: 200px" onclick="showLessreport();" value="预测量小于目标量的经销商名单" />
     </td>
  </tr>
</table>
<table class="table_query" id="tb2" style="display:none">
	<tr>
		<td align="center"><font color="red">没有满足条件的数据</font></td>
	</tr>
</table>
</body>
</html>
